package com.youxuan.util;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class BeanCopyUtils {

    public static <T> T copyBean(Object bean,Class<T> clazz){
        T t = null;
        try {
            t = clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        BeanUtils.copyProperties(bean,t);

        return t;
    }

    public static <O,T> List<T> copyList(List<O> list, Class<T> clazz){
        return list.stream().map(o -> copyBean(o, clazz)).collect(Collectors.toList());
    }

}
